package com.ai.bitcoin.jpa.dao;

import com.ai.bitcoin.jpa.entity.CoinPriceEstimate;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;

import java.util.List;

public interface CoinPriceEstimateDao extends JpaRepository<CoinPriceEstimate, String> {

    List<CoinPriceEstimate> findDistinctByBccIdAndLatest(String bccId, Integer latest);

    @Query(value="SELECT DISTINCT " +
            "bcc_basic_info.name_cn,bcc_basic_info.name_en,coin_price_estimate.prob,coin_price_estimate.bcc_id" +
            " FROM bcc_basic_info " +
            "left join coin_price_estimate on bcc_basic_info.bcc_id = coin_price_estimate.bcc_id " +
            "WHERE coin_price_estimate.latest = 1 AND market='blockcc' order by coin_price_estimate.prob DESC LIMIT 5", nativeQuery = true)
    List<Object> findTodayRecommend();
}
